package https.itmanager.com.springboot;

import com.itmanager.console.autoconfig.EnableEchoServer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

@SpringBootApplication
@EnableEchoServer
@MapperScan("https.itmanager.com.springboot.dao.mapper")
public class SpringbootApplication {


    public static void main(String[] args) throws Exception{
       // set();
      /// Thread.sleep(10000);
        //above is to spy the start detail
        runApp(args);
    }

    private static void runApp(String[] args){
        SpringApplication.run(SpringbootApplication.class, args);
    }

    public static void set() throws Exception{

        URL localURL = new URL("http://127.0.0.1:16888/spy/set?type=CommonTreeIntercepter&class=org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext&method=createWebServer&size=5");
        URLConnection connection = localURL.openConnection();
        HttpURLConnection httpURLConnection = (HttpURLConnection)connection;
        InputStream inputStream = null;
        InputStreamReader inputStreamReader = null;
        BufferedReader reader = null;
        StringBuffer resultBuffer = new StringBuffer();
        String tempLine = null;

        if (httpURLConnection.getResponseCode() >= 300) {
        }

        try {
            inputStream = httpURLConnection.getInputStream();
            inputStreamReader = new InputStreamReader(inputStream);
            reader = new BufferedReader(inputStreamReader);

            while ((tempLine = reader.readLine()) != null) {
                resultBuffer.append(tempLine);
            }

        } finally {

            if (reader != null) {
                reader.close();
            }

            if (inputStreamReader != null) {
                inputStreamReader.close();
            }

            if (inputStream != null) {
                inputStream.close();
            }

        }

        System.out.println("=============================================" + resultBuffer.toString());
    }

}
